package com.ad.pet.app.account;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.User;
import com.ad.pet.models.remote.account.AboutUs;

import javax.inject.Inject;

/**
 * Created by liuyixiang on 2019/10/29.
 */
@PerActivity
public class AboutUsPresenter  extends AbsBasePresenter implements AboutUsContract.Presenter{
    private ApiService mApiService;
    private AboutUsContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public AboutUsPresenter(ApiService apiService,
                            Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }


    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void onCreate(AboutUsContract.View view) {
        this.mView = view;
    }


    @Override
    public void aboutUs() {
        mRxDisposable.add(mApiService.about_us()
                .subscribe(new AppSubscriber<AboutUs>(mView) {
                    @Override
                    public void next(AboutUs keyWord) {
                        mView.aboutUsSuccess(keyWord);
                    }
                }));
    }

    @Override
    public void sendSuggesst(String content) {
        mRxDisposable.add(mApiService.sendSuggess(content)
                .subscribe(new AppSubscriber<User>(mView) {
                    @Override
                    public void next(User keyWord) {
                        mView.sendSuggessSuccess();
                    }
                }));
    }

    @Override
    public void clearAccount() {
        mRxDisposable.add(mApiService.cancellation()
                .subscribe(new AppSubscriber<User>(mView) {
                    @Override
                    public void next(User keyWord) {
                        mView.clearAccountSuccess();
                    }
                }));
    }
}
